//
//  SubjectItemView.m
//  JiaoX
//
//  Created by 尹桥印 on 14/11/12.
//  Copyright (c) 2014年 北京娇羞科技有限公司. All rights reserved.
//

#import "SubjectItemView.h"
#import "SubjectItemInfo.h"
#import "UIImageView+WebCache.h"

@interface SubjectItemView()
/** 顶部分割线 */
@property (nonatomic ,weak) UIView *view;
/** 商品图 */
@property (nonatomic, weak) UIImageView *subImage;
/** 标题图 */
@property (nonatomic, weak) UIImageView *titleIcon;
/** 标题 */
@property (nonatomic, weak) UILabel *titleLabel;
/** 描述 */
@property (nonatomic, weak) UILabel *descLabel;


@end
@implementation SubjectItemView
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = JXGlobalColorBg;
        [self addSubview:view];
        self.view = view;
        
        // 1.商品图
        UIImageView *subImage = [[UIImageView alloc]init];
        [self addSubview:subImage];
        self.subImage = subImage;
        
        // 2.标题前的icon
        UIImageView *titleIcon = [[UIImageView alloc]init];
        [self addSubview:titleIcon];
        self.titleIcon = titleIcon;
        
        // 3.标题
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.textColor = JXSubTitleColor;
        titleLabel.font = [UIFont boldSystemFontOfSize:JXSubTitleFont];
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        // 4.描述
        UILabel *descLabel = [[UILabel alloc] init];
        descLabel.textColor = JXSubDescColor;
        descLabel.font = [UIFont systemFontOfSize:JXSubDescFont];
        descLabel.numberOfLines = 0;
        [self addSubview:descLabel];
        self.descLabel = descLabel;
    }
    return self;
}

- (void)setSubjectFrame:(SubjectViewFrame *)subjectFrame
{
    _subjectFrame = subjectFrame;
    
    self.frame = subjectFrame.frame;
    
    // 设置分割线frame
    // 0.顶部分割线
    CGFloat viewX = 0;
    CGFloat viewY = 0;
    CGFloat viewW = JXScreenW;
    CGFloat viewH = JXPublicInset;
    self.view.frame = CGRectMake(viewX, viewY, viewW, viewH);
    
    // 取出专题数据
    SubjectItemInfo *subject = subjectFrame.subject;
    
    // 设置标题的Frame
    self.titleLabel.text = subject.subTiltleName;
    self.titleLabel.frame = subjectFrame.titleFrame;
    
    //设置标题图标的frame
    self.titleIcon.frame = subjectFrame.titleIconFrame;
    [self.titleIcon sd_setImageWithURL:[NSURL URLWithString:subject.subTiltleIcon]];
    
    
    // 设置图片的Frame
    self.subImage.frame = subjectFrame.subImageFrame;
    [self.subImage sd_setImageWithURL:[NSURL URLWithString:subject.subImage]];
    
    // 设置描述
    self.descLabel.text = subject.subDesc;
    self.descLabel.frame = subjectFrame.descLabelFrame;
    
}


@end
